﻿<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Plain.Demo.Blog.Business.Post>>" MasterPageFile="~/Layout/OneColumn.master" %>
<asp:Content id="ctnHead" runat="server" ContentPlaceHolderID="Head">
	<script type="text/javascript" >
		$(function() {
			$(".ShowContent").toggle(function(event){
				event.preventDefault();
				$(this).parent().parent().next().fadeIn("slow");
				return false;
			}, function(event){
				event.preventDefault();
				$(this).parent().parent().next().fadeOut("slow");
				return false;
			});
			
			$(".ShowComment").toggle(function(event){
				event.preventDefault();
				$(this).parent().parent().next().nextAll().each( function() { 
           			if ($(this).hasClass("Post") != false) { 
				        return false;
				    }
				    if($(this).hasClass("Comment") != false){
           				$(this).fadeIn("slow");
           			}
           		}); 
				return false;
			}, function(event){
				event.preventDefault();
				$(this).parent().parent().next().nextAll().each( function() { 
           			if ($(this).hasClass("Post") != false) { 
				        return false;
				    }
				    if($(this).hasClass("Comment") != false){
           				$(this).fadeOut("slow");
           			}
           		}); 
				return false;
			});
			
			$(".ShowCommentContent").toggle(function(event){
				event.preventDefault();
				$(this).parent().parent().next("tr.CommentContent").fadeIn("slow");
				return false;
			}, function(event){
				event.preventDefault();
				$(this).parent().parent().next("tr.CommentContent").fadeOut("slow");
				return false;
			});
			
			$("a.Delete").click(function(event){
				event.preventDefault();
				var a = $(this);
				$.post("<%= Url.Action("Delete","Post") %>/" + a.attr("id"),
					function(data){
						a.parent().parent().nextAll().each( function() { 
							if ($(this).hasClass("Post") != false) { 
				     		   return false;
				    		}
							$(this).remove();
						});
						a.parent().parent().remove();
					});
				return false;
			});
			
			$("a.DeleteComment").click(function(event){
				event.preventDefault();
				var a = $(this);
				$.post("<%= Url.Action("Delete","Comment") %>/" + a.attr("id"),
					function(data){
						a.parent().parent().next().remove();
						a.parent().parent().remove();
					});
				return false;
			});
			
			$("").click(function(event){
				event.preventDefault();
				
				$.post("<%=Url.Action("Published","Post") %>",
					function(data){
						$.each(data,function(item){
						});
					});
				
				return false;
			});
		});
	</script>
</asp:Content>
<asp:Content id="ctnSingleColumn" runat="server" ContentPlaceHolderID="SingleColumn">
	<ul id="Panel">
    	<li><%= Html.ActionLink("Create","Create","Post") %></li>
    	<li><%= Html.ActionLink("About me","Edit","User", new { id=1 },null) %></li>
    	<li class="Filter">Filter:</li>
    	<li><a href="#" id="Draft">Draft</a></li>
    	<li><a href="#" id="Published">Published</a></li>
    	<li><a href="#" id="Scheduled">Scheduled</a></li>
    </ul>
	<table id="Posts">
		<% foreach (var post in Model) { %> 
			<tr class="Post">
		    	<td class="Subpanel">
		    		<a href="<%= Url.Action("Edit", new { id=post.Id }) %>"><img src="/Images/author-24.png" alt="Edit post" /></a>
		    	</td>
		    	<td class="Subpanel">
		    		<a href="#" class="ShowContent"><img src="/Images/article-24.png" alt="View post" /></a>
		    	</td>
		    	<td class="Subpanel">
		    		<a href="#" class="ShowComment"><img src="/Images/comments-24.png" alt="View comments" /></a>
		    	</td>	
				<td>
					<%= post.Title %>
				</td>
		    	<td class="Status">
		    		<% if(post.Published != null && post.Published.Value <= DateTime.Now){ %>
		    			Published (<%= post.Published.Value.ToString("dd/MM/yyyy") %>)
		    		<% } else if(post.Published != null && post.Published.Value > DateTime.Now){ %>
		    			Scheduled (<%= post.Published.Value.ToString("dd/MM/yyyy") %>)
		    		<% } else{ %>
		    			Draft
		    		<% } %>
		    	</td>
		    	<td>
		    		<%= post.Created.ToString("dd/MM/yyyy") %>
		    	</td>
		    	<td>
		    		<i>by</i> <%= post.Author.FirstName %> <%= post.Author.LastName %>
		    	</td>
		    	<td class="Subpanel">
		    		<a href="#" id="<%= post.Id %>" class="Delete"><img src="/Images/delete_32x32.png" alt="Delete post" /></a>
		    	</td>
		    </tr>
		    <tr class="Content">
		    	<td colspan="8">
		    		<%= post.Content %>
		    	</td>
		    </tr>
		    <% foreach (var comment in post.Comments) { %> 
			    <tr class="Comment">
			    	<td>
			    	</td>
			    	<td class="Subpanel">
			    		<a href="<%= Url.Action("Edit","Comment", new { id=comment.Id }) %>"><img src="/Images/author-24.png" alt="Edit comment" /></a>
			    	</td>
			    	<td class="Subpanel">
		    			<a href="#" class="ShowCommentContent"><img src="/Images/article-24.png" alt="View comment" /></a>
		    		</td>
			    	<td>
			    		<i>comment by</i> <%= comment.Author %>
			    	</td>
			    	<td>
			    		<%= comment.Email %>
			    	</td>
			    	<td>
			    		<%= comment.IpAddress %>
			    	</td>
			    	<td>
			    		<%= comment.Created.ToString("dd/MM/yyyy") %>
			    	</td>
			    	<td class="Subpanel">
			    		<a href="#" id="<%= comment.Id %>" class="DeleteComment"><img src="/Images/delete_32x32.png" alt="Delete comment" /></a>
			    	</td>
			    </tr>
			    <tr class="CommentContent">
			    	<td>
			    	</td>
			    	<td colspan="7">
			    		<%= comment.Content %>
			    	</td>
			    </tr>
		    <% } %>
		<% } %>
	</table>
</asp:Content>  